﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MillerApp.UserControls;
using MillerApp.DataContract.MillerDB;
using MillerApp.DataAccess.MillerDB;
using MillerApp.DataContract.Common;

namespace MillerApp.Stock
{
    public partial class CommonTypeMaintain : EnitityFormBase
    {
        public CommonTypeMaintain()
        {
            InitializeComponent();
        }

        public CommontypeEntity Entity { get; set; }

        private void CommonTypeMaintain_Load(object sender, EventArgs e)
        {
            object obj = Entity;
            base.Mapping2Control(ref obj);
            this.maintainActionControl1.ActionMethod += new DelegateMethod(maintainActionControl1_ActionMethod);
        }

        void maintainActionControl1_ActionMethod()
        {
            if (this.ActionTypeCode == UserControls.Enums.ActionType.Deleted)
            {
                CommontypeManager.DeleteCommontype(Entity.id);
                return;
            }

            if (this.ActionTypeCode == UserControls.Enums.ActionType.AddNew)
            {
                Entity = new CommontypeEntity();
                object obj = Entity;
                base.Mapping2Entity(ref obj);
                CommontypeManager.InsertCommontype(Entity);
            }
            if (this.ActionTypeCode == UserControls.Enums.ActionType.Modify)
            {
                object obj = Entity;
                base.Mapping2Entity(ref obj);
                CommontypeManager.UpdateCommontype(Entity);
            }
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }
    }
}
